# -*- encoding=utf8 -*-
from time import sleep
from airtest.core.api import *
from apicore.PocoApi import PocoApi
from base_page.Home import Home
from api.utils.LoggerHelp import logger

class Phone_Home(PocoApi):
    def __init__(self):
        super().__init__()
        self.home = Home()

    # 进入云手机页面
    def enter_page(self):
        self.home.phone_home()

    # 进入一键安装
    def one_click_installation(self):
        self.enter_page()
        self.home.poco_click(text="一键安装")

    # 进入秒装秒玩
    def one_piece_installation(self):
        self.enter_page()
        self.home.poco_click(text="秒装秒玩")
        logger.info("秒装秒玩")

    # 进入一键上云
    def one_click_cloud_migration(self):
        self.enter_page()
        self.home.poco_click(text="一键上云")

    # 进入备份恢复
    def backup_and_restore(self):
        self.enter_page()
        self.home.poco_click(text="恢复备份")
    #图标设置按钮
    def icon_settings(self):
        self.enter_page()
        self.home.poco_click("com.unicom.cloudphone:id/ib_settings")
        logger.info("点击图标设置按钮")

    # 进入云机
    def enter_the_cloud_machine(self):
        self.enter_page()
        self.home.poco_click(text="启动云机")
        logger.info("点击进入云机按钮")
        try:
            # 等待图像出现
            quxiao = wait(
                Template(self.base_path + "/images/cloudphonehome/" + "quxiao.png", record_pos=(0.148, 0.146),
                         resolution=(1080, 2340)), timeout=5, interval=0.5)
            # 点击找到的图像
            touch(quxiao)
        except Exception as e:
            print(f"进入云机失败，错误信息：{e}")
            log(f"进入云机失败，错误信息：{e}")

    # 退出云机
    def exit_cloudin(self):  ##退出云机
        self.home.poco_click("com.unicom.cloudphone:id/iv_more")
        self.home.poco_click(text="退出云手机")